package com.czh.springboot04.MyController;

import com.czh.springboot04.entity.Company;
import com.czh.springboot04.service.CompanyService;
import com.czh.springboot04.util.R;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/company")
public class CompanyCotroller {
    @Autowired
    private CompanyService companyService;
    @PostMapping("/companyAdd")
public R companyAdd(@RequestBody Company company){
    int i = companyService.companyAdd(company);
    if (i>0){
        return R.ok(i);
    }
    return R.fail("添加失败");
}
@PutMapping("/companyUpdate")
public R companyUpdate(@RequestBody Company company){
    int i = companyService.companyUpdate(company);
    if (i>0){
        return R.ok(i);
    }
    return R.fail("修改失败");
}
@PostMapping("/companyDelete")
    public R companyDelete(@RequestBody int id){
    int i = companyService.companyDelete(id);
    if (i>0){
        return R.ok(i);
    }
    return R.fail("删除失败");
}
@GetMapping("/companySelectAll")
    public R companySelectAll(@RequestParam(required = false, defaultValue =  "1") int pageNum,
                              @RequestParam(required = false, defaultValue =  "3") int pageSize,
                              Company company){
    PageInfo<Company> companies = companyService.companySelectAll(pageNum, pageSize, company);
    if (companies!=null){
        return R.ok(companies);
    }else{
        return R.fail("查询失败");
    }

}

}
